using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Xml;
using RBAC.ErrorCode;
using RBAC.Write.Api.Application.Command.ProductionPlans;

namespace RBAC.Write.Api.Controllers
{
    /// <summary>
    /// 生产计划控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionPlanWriteController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProductionPlanWriteController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 新增生产计划（支持按 GoodsIds 批量创建多条）
        /// </summary>
        [HttpPost]
        public Task<APIResult<int>> AddProductionPlan([FromBody] AddProductionPlanCommands request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 删除生产计划（软删除）
        /// </summary>
        [HttpDelete("{ProductionPlanId:long}")]
        public Task<APIResult<int>> DeleteProductionPlan([FromRoute] long ProductionPlanId, CancellationToken cancellationToken)
        {
            var cmd = new DeleteProductionPlanCommands { ProductionPlanId = ProductionPlanId };
            return mediator.Send(cmd, cancellationToken);
        }

        /// <summary>
        /// 修改生产计划
        /// </summary>
        [HttpPut]
        public Task<APIResult<int>> UpdateProductionPlan([FromBody] UpdateProductionPlanCommands request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }


    }
}
